package structures;

public class Granule implements main.Initializable
{
	private double activationThreshold;
	private double toMitralWeight;
	public final String stringRepresentation;
	private double activation;
	private boolean isInitialized;
	private boolean activated;
	
	@Deprecated
	public Granule()
	{
		activationThreshold = -1;
		toMitralWeight = -1;
		stringRepresentation = null;
		activation = 0;
		this.isInitialized = false;
		this.activated = false;
	}
	
	/**
	 * Creates new granule given parameters
	 * 
	 * @param activationThreshold
	 * @param toMitralWeight - multiplicative mitral inhibition weight
	 * @param parent - column wherein this granule lives
	 * @param n - the network wherein this granule lives
	 * @param granuleNum - arbitrary number assigned to granule
	 * 
	 * @throws InitializationException if initalization fails
	 */
	public Granule(double activationThreshold, double toMitralWeight, Column parent, Network n, int granuleNum) 
			throws main.InitializationException 
	{
		this.activationThreshold = activationThreshold;
		this.toMitralWeight = toMitralWeight;
		this.stringRepresentation = "G"+n.indexOf(parent)+"-"+granuleNum;
		this.activation = 0;
		this.activated = false;
		
		this.initialize(new Object());
		
		//DEBUG
		if(main.Main.VERBOSE)
		{
			System.out.println(this.stringRepresentation+" has MW: "+this.toMitralWeight+", AT: "+this.activationThreshold);
		}
		
		//LOG
		if(main.Main.LOG_WRITER != null)
		{
			main.Main.attemptNewLineToLog();
			main.Main.attemptWriteToLog(this.stringRepresentation+" has MW: "+this.toMitralWeight+", AT: "+this.activationThreshold);
		}
	}
	
	public boolean isActive()
	{
		return this.activated;
	}
	
	protected void setActivated(boolean isActive)
	{
		this.activated = isActive;
	}
	
	protected double getActivation()
	{
		return this.activation;
	}
	
	protected void setActivation(double activation)
	{
		this.activation = activation;
	}
	
	public double getActivationThreshold()
	{
		return this.activationThreshold;
	}
	
	/**
	 * Granule-to-Mitral weight
	 * @return
	 */
	public double getMitralWeight()
	{
		return this.toMitralWeight;
	}
	
	@Override
	public String toString()
	{
		return this.stringRepresentation;
	}

	public void initialize(Object params) throws main.InitializationException 
	{
		if(this.stringRepresentation != null)
			this.isInitialized = true;
	}

	public boolean isInitialized()
	{
		return this.isInitialized;
	}
}
